package org.dromara.system.domain.bo;

import io.github.linpeilie.annotations.AutoMapper;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.mybatis.core.domain.BaseEntity;
import org.dromara.system.domain.SysFaultInfoEn;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;

/**
 * English Fault Information Management Business Object (Composite BO)
 * For front-end submission of fault information and solution joint operations
 *
 * @author system
 */
@Data
@EqualsAndHashCode(callSuper = true)
@AutoMapper(target = SysFaultInfoEn.class, reverseConvertGenerate = false)
public class SysFaultManageEnBo extends BaseEntity {

    /**
     * Fault ID
     */
    @NotNull(message = "Fault ID cannot be empty", groups = { EditGroup.class })
    private Long faultId;

    /**
     * Excavator Model
     */
    @NotBlank(message = "Excavator model cannot be empty", groups = { AddGroup.class, EditGroup.class })
    private String excavatorModel;

    /**
     * Fault Part
     */
    @NotBlank(message = "Fault part cannot be empty", groups = { AddGroup.class, EditGroup.class })
    private String faultPart;

    /**
     * Fault Symptom
     */
    @NotBlank(message = "Fault symptom cannot be empty", groups = { AddGroup.class, EditGroup.class })
    private String faultSymptom;

    /**
     * Detailed Fault Description
     */
    @NotBlank(message = "Fault detail cannot be empty", groups = { AddGroup.class, EditGroup.class })
    private String faultDetail;

    /**
     * Fault Remark
     */
    private String remark;

    // ==================== Solution Related Fields ====================

    /**
     * Solution Action Type
     * - none: Do not process solution
     * - upload: Upload new solution file
     * - link: Link existing solution
     * - replace_upload: Replace existing solution (upload new file)
     * - remove: Remove solution link
     * - keep: Keep current solution unchanged
     */
    private String solutionAction = "none";

    /**
     * Solution Document ID (for linking existing document)
     */
    private Long linkDocId;

    /**
     * Solution Folder Name (for upload)
     */
    private String solutionFolderName;

    /**
     * Solution Remark
     */
    private String solutionRemark;

    /**
     * Delete Old Solution Document (used during replacement)
     * true: Delete old document (if not referenced by other faults)
     * false: Keep old document
     */
    private Boolean deleteOldSolution = true;

    // ==================== Helper Methods ====================

    /**
     * Convert to Fault Info BO
     */
    public SysFaultInfoEnBo toFaultInfoBo() {
        SysFaultInfoEnBo faultBo = new SysFaultInfoEnBo();
        faultBo.setFaultId(this.faultId);
        faultBo.setExcavatorModel(this.excavatorModel);
        faultBo.setFaultPart(this.faultPart);
        faultBo.setFaultSymptom(this.faultSymptom);
        faultBo.setFaultDetail(this.faultDetail);
        faultBo.setRemark(this.remark);
        return faultBo;
    }

    /**
     * Check if need to upload solution file
     */
    public boolean needUploadSolution() {
        return "upload".equals(solutionAction) || "replace_upload".equals(solutionAction);
    }

    /**
     * Check if need to link existing solution
     */
    public boolean needLinkSolution() {
        return "link".equals(solutionAction) && linkDocId != null;
    }

    /**
     * Check if need to remove solution
     */
    public boolean needRemoveSolution() {
        return "remove".equals(solutionAction);
    }

    /**
     * Check if keep solution unchanged
     */
    public boolean keepSolution() {
        return "keep".equals(solutionAction) || "none".equals(solutionAction);
    }
}

